London 9 -Marziyeh Azhdari - JS-Core-1 - Week 1 #429
Conversation
Gayle-Thompson-Igwebike
left a comment
There was a problem hiding this comment.
Great job Marziyeh. Well done.
|
|
||
| let first="Hello, my name is " | ||
| let myName="Mari" | ||
| let message=first+myName |
There was a problem hiding this comment.
I like how you concatenated the first+myName in the variable. I did it the very long way.... This is good.
| @@ -1,5 +1,7 @@ | |||
| // Write your function here | |||
| function greeting(name){ | |||
| console.log("Hello,my name is ;"+(name)); | |||
There was a problem hiding this comment.
Hi Marziyeh, Just looking at this code and I thought, I would have written it like this:
console.log("Hello, my name is " + name);
What do you think?
|
|
||
| function convertToUSD() {} | ||
| function convertToUSD(price) { | ||
| return price*1.4 |
There was a problem hiding this comment.
I like this syntax...mine was sooo long... Great job.
| @@ -1 +1,6 @@ | |||
| console.log("Hello world"); | |||
| console.log("cd exercises/B-hello-world") | |||
There was a problem hiding this comment.
Interesting test! I hope you realised that this will still just print "cd exercises/B-hello-world", even if this command has a very different meaning when you run it in the console, that is, this will not change directory when run inside the console.log as a string.
| let myName="mari" | ||
| let lengthName=myName.length | ||
| // let messageTwo=`my name is${myName}and my name is${lengthName}characters long` | ||
| let message=" My name is"+myName+" and my name is " + lengthName+" characters long" |
There was a problem hiding this comment.
This is a very small comment, but you should try to be consistent with your style. If you are putting spaces before and after the plus signs, for example. is" + myName + " an you should do that for all strings concatenations.
There was a problem hiding this comment.
I used the .trim method to remove the extra whitespace for this I made space. so I should do that for all strings concatenations??
There was a problem hiding this comment.
Thanks @mcarballopacheco Your suggestion is quite right. I'm practising consistency also. Javascript is soo hard for me
| let total=numberOfMentors+numberOfStudents | ||
| let percentageOfStudent=numberOfStudents/total*100; | ||
| console.log("Percentage students: "+Math.round(percentageOfStudent)+"%"); | ||
| let PercentageMentors=100-percentageOfStudent |
There was a problem hiding this comment.
You could have also calculated the percentage of mentors, as.
let PercentageMentors=numberOfMentors/total*100;
and then use round. Surprisingly, this may not always be the same as the way you calculated it, because if the fraction ends in 0.5, it will always go up to the next integer when using Math.round. This is why in general, it is important to be aware and careful when rounding up numbers.
| @@ -1,5 +1,7 @@ | |||
| // Write your function here | |||
| function greeting(name){ | |||
| console.log("Hello,my name is ;"+ name); | |||
There was a problem hiding this comment.
I think here it would have make more sense based on the exercise to return the greeting and then use console.log() outside of the function.
There was a problem hiding this comment.
function greeting(name){
return name;
}
console.log("Hello,my name is ;"+greeting("Daniel"));
Is it ok?
| // Call the function and assign to a variable `sum` | ||
|
|
||
| console.log(sum); | ||
| console.log(sum(13,124)); |
There was a problem hiding this comment.
This will work, but in the exercise it mentioned to assign the value to a variable called sum, so:
let sum = add(13, 124)
console.log(sum)
| function result(name){ | ||
| return console.log(greeting(name)); | ||
| } | ||
| result(mentor1); |
| // Why can this code be seen as bad practice? Comment your answer. | ||
| //there are three functions that are not necessary and I think it is possible with a shorter code as well.(I am not sure!!!!!!!!!!!!!!!!!) | ||
| let badCode = | ||
|
|
There was a problem hiding this comment.
It is in general a bad idea to call many functions in the same line. It makes the code very hard to read. A better idea is to call each function once in a line and assign the result to a variable which then gets called in the following like but the next function, etc.
| @@ -1,17 +1,24 @@ | |||
| // Add comments to explain what this function does. You're meant to use Google! | |||
| //The Math.random() function returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, | |||
| function getRandomNumber() { | |||
There was a problem hiding this comment.
I think here, the question is asking what does the getRandomNumber() does also?
|
|
||
| function addTaxAndFormatCurrency() {} | ||
| function addTaxAndFormatCurrency(price) { | ||
| return `£${(price * 1.2).toFixed(2)}`; |
There was a problem hiding this comment.
You should have used the calculateSalesTax function that you just created. The reason we create functions is to not repeat code which minimises errors. For example, let say the sales tax changes from 20% to 25%. if all of the times you calculated the sales tax you always use the calculateSalesTax function, then you only need to change the calculation in one place only. But if you are calculating in different places, then you would have to find them one by one.
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?